package com.psg.interceptor;

import com.psg.pojo.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class UserInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User loginUser =(User) request.getSession().getAttribute("login");
        if (null==loginUser){
            response.sendRedirect("/user/toLogin");
            return false;
        }else {
            return true;
        }
    }
}
